<template>
  <div v-if="dataSource.list && dataSource.list.length == 0">
    <no-data msg="空空如也"></no-data>
  </div>
  <div class="data-list-panel">
    <template v-for="item in dataSource.list">
      <slot :data="item"></slot>
    </template>
  </div>
  <div class="pagination" v-if="showPagination && dataSource.pageTotal > 1">
    <el-pagination
      background
      :total="dataSource.totalCount"
      :current-page.sync="dataSource.pageNo"
      layout="prev,pager,next,"
      @current-change="handlePageNoChange"
      :page-size="dataSource.pageSize"
    ></el-pagination>
  </div>
</template>

<script setup lang="ts">
const props = withDefaults(
  defineProps<{
    dataSource: any
    showPagination?: boolean
  }>(),
  {
    showPagination: true
  }
)
const emit = defineEmits(['loadData'])
const handlePageNoChange = (pageNo: number) => {
  props.dataSource.pageNo = pageNo
  emit('loadData')
}
</script>

<style lang="less" scoped>
.data-list-panel {
  max-height: calc(100% - 50px);
  overflow: auto;
}
.pagination {
  padding: 10px 0px 5px 0px;
  text-align: right;
  overflow: hidden;
  height: 50px;
  :deep(.el-pagination) {
    float: right;
  }
}
</style>
